import { Tool } from '../../../Tool';

/**
 * 构件透明度
 */
export class ComponentTransparentTool extends Tool {
	constructor(viewer, transparent) {
		super(arguments);
		this.viewer = viewer;
		this.transparent = transparent || 0.2;
		this.layers = [];
		this.handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
	}

	start() {
		this.handler.setInputAction((e) => {
			const pick = this.viewer.scene.pick(e.position);
			if (!pick) return;
			const layer = pick?.primitive;

			this.layers.push(layer);
			layer.setObjsColor(pick.id, Cesium.Color.WHITE.withAlpha(Number(this.transparent)));
		}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
	}

	cancel() {
		this.handler?.destroy();
		for (const layer of this.layers) {
			layer.removeAllObjsColor();
		}
	}
}
ComponentTransparentTool.toolId = 'ComponentTransparentTool';
